#include "EditorBreakpointAbilityViewModel.h"

#include "Asset/EditorDefaultPackage.h"
#include "Language/EditorScriptDebugSubsystem.h"

#include "Framework/Editor.h"
#include "Theme/EditorTheme.h"


void REditorBreakpointAbilityViewModel::BindModel(TSharedObjectPtr<REditorAbilityModel> InModel)
{
    Super::BindModel(InModel);
    BreakpointModel = InModel;

    Icon = REditorDefaultPackage::Get()->GetIcon(U"CodiconDebugAlt");
    HighlightIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconDebugAlt_Highlight");

    BreakpointSubsystem= REditor::Get()->GetSubsystem<REditorScriptDebugSubsystem>();
    BreakpointSubsystem->OnBreakpointAdded.BindLambda([this](const CString & InFileId, int64_t InLineIndex)
    {
        OnBreakpointAdded.ExecuteIfBound();
    });

    BreakpointSubsystem->OnBreakpointRemoved.BindLambda([this](const CString & InFileId, int64_t InLineIndex)
    {
        OnBreakpointRemoved.ExecuteIfBound();
    });

}

TSharedObjectPtr<RTexture2D> REditorBreakpointAbilityViewModel::GetIcon() const
{
    return Icon;
}

TSharedObjectPtr<RTexture2D> REditorBreakpointAbilityViewModel::GetHighlightIcon() const
{
    return HighlightIcon;
}

SColor REditorBreakpointAbilityViewModel::GetBreakpointColor(int64_t InBreakpointIndex)
{
    if (IsBreakpointEnabled(InBreakpointIndex))
    {
        return  REditor::Get()->CurrentTheme->BreakpointColor;
    }
    else
    {
        return REditor::Get()->CurrentTheme->DisabledDebugPointColor;
    }
}

int64_t REditorBreakpointAbilityViewModel::GetBreakpointNumber() const
{
    return BreakpointSubsystem->GetBreakpointNumber();
}

bool REditorBreakpointAbilityViewModel::IsBreakpointEnabled(int64_t InBreakpointIndex) const
{
    return BreakpointSubsystem->IsBreakpointEnabled(InBreakpointIndex);
}

void REditorBreakpointAbilityViewModel::TogglerBreakpointEnabled(int64_t InBreakpointIndex)
{
    BreakpointSubsystem->TogglerBreakpointEnabled(InBreakpointIndex);
}

CString REditorBreakpointAbilityViewModel::GetBreakpointFileName(int64_t InBreakpointIndex) const
{
    return BreakpointSubsystem->GetBreakpointFileName(InBreakpointIndex);
}

CString REditorBreakpointAbilityViewModel::GetBreakpointFilePath(int64_t InBreakpointIndex) const
{
    return BreakpointSubsystem->GetBreakpointFilePath(InBreakpointIndex);
}

int64_t REditorBreakpointAbilityViewModel::GetBreakpointLine(int64_t InBreakpointIndex) const
{
    return BreakpointSubsystem->GetBreakpointLine(InBreakpointIndex);
}

void REditorBreakpointAbilityViewModel::RemoveBreakpoint(int64_t InBreakpointIndex)
{
    BreakpointSubsystem->RemoveBreakpoint(InBreakpointIndex);
}
